<?php
	/**
	* 其他信息
	*/
	class ComOtherInfoModel extends Model
	{
		public $table = 'company_otherinfo';
		public $auto = array(
				array('licensestatus','1','string',2,1),
				array('user_uid','_uid','method',2,3)
			);

		public function _uid()
		{
			return session('uid');
		}

		public function add_character_data()
		{
			$upload = new upload();
			$uploadFile = $upload->upload();

			if(!$uploadFile){

				$this->error = $upload->error;
				return false;
			}
			// p($uploadFile);
			$user_uid = session('uid');
			$data = array(
				'licensestatus'=>1,
				'user_uid' => $user_uid,
				'licensepic' => $uploadFile[0]['path'],
				'license' => Q('post.license')
				);
			$where = array('user_uid'=>$user_uid);
			// p($data);
			$oldPic = $this->where($where)->getField('licensepic');

			if(!$oldPic)return $this->add($data);
			$oldPicFile = ROOT_PATH.$oldPic;

			if (is_file($oldPicFile)) {
				$picInfo = pathinfo($oldPicFile);
				unlink($oldPicFile);
				$oldPicThumb = $picInfo['dirname'] . '/' .$picInfo['filename'].'_thumb' . '.'.$picInfo['extension'];
				is_file($oldPicThumb)  || unlink($oldPicThumb);
			}

			return $this->where($where)->save($data);
		}



		public function update_logo()
		{
			$upload = new upload();
			$uploadFile = $upload->upload();

			if(!$uploadFile){

				$this->error = $upload->error;
				return false;
			}
			// p($uploadFile);
			$user_uid = session('uid');
			$where = array('user_uid'=>$user_uid);
			$data = array(
				'logo' => $uploadFile[0]['path'],
				);
 			$oldPic = $this->where($where)->getField('logo');
			$info = $this->have_data($user_uid);
			if(!$oldPic){
				if(!$info){
					$this->error='请先上传营业执照';
					return false;
				}else{
					return $this->where($where)->save($data);
				}
				
			}
			$oldPicFile = ROOT_PATH.$oldPic;

			if (is_file($oldPicFile)) {
				$picInfo = pathinfo($oldPicFile);
				unlink($oldPicFile);
				$oldPicThumb = $picInfo['dirname'] . '/' .$picInfo['filename'].'_thumb' . '.'.$picInfo['extension'];
				is_file($oldPicThumb)  || unlink($oldPicThumb);
			}

			return $this->where($where)->save($data);



		}


		public function have_data($user_uid)
		{
			$user_uid = session('uid');
			$where = array('user_uid'=>$user_uid);
			return $this->where($where)->find();
		}


		/**
	     * 改变审核状态
	     * @return [type] [description]
	     */
	    public function change_verify($where,$verify){
	    	// p($where);exit;
	        $this->where($where)->save(array('licensestatus'=>$verify));
	    }
	}
?>